<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<div class="easyui-layout" style="height:700px;">
	<div data-options="region:'center',split:false"
			style="width:600px;padding:5px">
		<table class="easyui-datagrid" id="mapList" title="映射列表">
		</table>
	</div>
	<div data-options="region:'west',split:false"
			style="width:600px;padding:5px">
			<ul id="testCategoryMap" class="easyui-tree">
			</ul>
	</div>
</div>
<shiro:hasRole name="admin">
<script>
$(function(){
		$('#mapList').datagrid({
		url:'/map/querymapbycat',
		toolbar:[{
			iconCls: 'icon-cancel',
			handler: function(){
				var ids = TT.getSelectionsIds("#mapList");
		    	if(ids.length == 0){
		    		$.messager.alert('提示','未选中行!');
		    		return ;
		    	}
		    	$.messager.confirm('确认','确定删除吗？',function(r){
		    	    if (r){
		    	    	var params = {"ids":ids};
		            	$.post("/map/delete",params, function(data){
		        			if(data.status == 200){
		        				$.messager.alert('提示','删除内容成功!',undefined,function(){
		        					$("#mapList").datagrid("reload");
		        				});
		        			}
		        		});
		    	    }
		    	});
			},
			text:'删除映射'
		},'-',{
			iconCls: 'icon-search',
			handler: function(){
				var ids = TT.getSelectionsIds("#mapList");
				var strs= new Array();
				var split =ids.split(",");
				for (var i in split) {
					strs.push(split[i]);
				}
				if(strs[0]==null || strs[0]==""){
					$.messager.alert('提示','未选中任何映射!');
					return;
				} else {
					if(strs[1]==null || strs[1]==""){
						TAOTAO.createWindow({
	        				url : "/map/detail?id="+ids,
	        			});
					} else {
						$.messager.alert('提示','只能选择一条!');
	        			return ;
					}
				}
			},
			text:'查看详情'
		},"-",{
			iconCls:'icon-save',
			handler:function(){
				var ids = TT.getSelectionsIds("#mapList");
				//console.log('ids: '+ids);
				var strs= new Array();
				var split =ids.split(",");
				for (var i in split) {
					strs.push(split[i]);
				}
				if(strs[0]==null || strs[0]==""){
					$.messager.alert('提示','未选中任何映射!');
					return;
				} else {
					var url = "/map/output?ids="+ids;
					window.open(url);
				}
			},
			text:'导出'
		}],
		striped:true,
		singleSelect:false,
		collapsible:true,
		pagination:true,
		method:'get',
		pageSize:30,
		columns:[[
			{field:'ck',checkbox:true },
			{field:'caseNo',width:80,title:'测试用例编号'},
			{field:'caseText',width:500,title:'测试用例'},
			{field:'designNo',width:80,title:'需求编号'},
			{field:'designText',width:300,title:'设计需求'},
			{field:'createdTime',width:130,title:'建立时间',
				formatter:TAOTAO.formatDateTime
			}
		]]
	
	});


	var tree3 = $("#testCategoryMap");
		tree3.tree({
		url : '/test/category/list',
		animate: true,
		method : "GET",
		lines:true,
		onClick : function(node){
			var id = tree3.tree("getSelected").id;
			//console.log('id: '+id);
			$.ajax({
					url:'/map/querymapbycat',
					data:{
						id:id
						},
					dataType:'json',
					success:function(data) {
						$("#mapList").datagrid("reload");
					}
					
				
				})
		}
	});
	
})
    
</script>

</shiro:hasRole>
<shiro:hasRole name="guest">
	<script>
$(function(){
		$('#mapList').datagrid({
		url:'/map/querymapbycat',
		toolbar:[{
			iconCls: 'icon-search',
			handler: function(){
				var ids = TT.getSelectionsIds("#mapList");
				var strs= new Array();
				var split =ids.split(",");
				for (var i in split) {
					strs.push(split[i]);
				}
				if(strs[0]==null || strs[0]==""){
					$.messager.alert('提示','未选中任何映射!');
					return;
				} else {
					if(strs[1]==null || strs[1]==""){
						TAOTAO.createWindow({
	        				url : "/map/detail?id="+ids,
	        			});
					} else {
						$.messager.alert('提示','只能选择一条!');
	        			return ;
					}
				}
			},
			text:'查看详情'
		},"-",{
			iconCls:'icon-save',
			handler:function(){
				var ids = TT.getSelectionsIds("#mapList");
				//console.log('ids: '+ids);
				var strs= new Array();
				var split =ids.split(",");
				for (var i in split) {
					strs.push(split[i]);
				}
				if(strs[0]==null || strs[0]==""){
					$.messager.alert('提示','未选中任何映射!');
					return;
				} else {
					var url = "/map/output?ids="+ids;
					window.open(url);
				}
			},
			text:'导出'
		}],
		striped:true,
		singleSelect:false,
		collapsible:true,
		pagination:true,
		method:'get',
		pageSize:10,
		columns:[[
			{field:'ck',checkbox:true },
			{field:'caseNo',width:80,title:'测试用例编号'},
			{field:'caseText',width:500,title:'测试用例'},
			{field:'designNo',width:80,title:'需求编号'},
			{field:'designText',width:300,title:'设计需求'},
			{field:'createdTime',width:130,title:'建立时间',
				formatter:TAOTAO.formatDateTime
			}
		]]
	
	});


	var tree3 = $("#testCategoryMap");
		tree3.tree({
		url : '/test/category/list',
		animate: true,
		method : "GET",
		lines:true,
		onClick : function(node){
			var id = tree3.tree("getSelected").id;
			//console.log('id: '+id);
			$.ajax({
					url:'/map/querymapbycat',
					data:{
						id:id
						},
					dataType:'json',
					success:function(data) {
						$("#mapList").datagrid("reload");
					}
					
				
				})
		}
	});
	
})
    
</script>
</shiro:hasRole>